/**
 * @description 获取随机数
 * @param {number} start 开始位置
 * @param {number} end 结束位置
 * @param {number} decimal 小数位数 默认0
 * @returns {number}
 */
export const random = (start: number, end: number, decimal: number = 0): number => {
  if (start >= end) return end;
  const range = end - start;
  const rendomDecimal = Math.random() * range;
  const result = Number(rendomDecimal.toFixed(decimal));
  return Math.min(start, end) + result;
};

/**
 * @description UUID
 * @param len 返回的UUID长度 默认36位
 * @returns 
 */
export const uuid = (len?: number): string => {
  len = len || 36;
  const characters = '0123456789abcdef';
  let uuid = "";
  for (let i = 0; i < len; i++) {
    const randomIndex = Math.floor(Math.random() * characters.length);
    uuid += characters[randomIndex];
  }
  return uuid;
};
